module test_triangle_mod

use pFUnit

use test_point_mod
use triangle_mod

implicit none

!> Overload the pFUnit assert for triangles
interface assertEqual
    module procedure assertEqual_triobj
end interface

contains

subroutine Run_Triangle_Tests()
    type(TestSuite_type)  :: suite
    type(TestResult_type) :: result
    character(len=100) :: summary_statement

    ! Build suite from test procedures:
    suite = TestSuite( 'Test triangle_mod' )
    call add ( suite, TestCase1Step ( 'Test_Triangle_Create', Test_Triangle_Create ) )
!    call add ( suite, TestCase1Step ( 'test_meshcreate',   test_meshcreate   ) )
!    call add ( suite, TestCase1Step ( 'test_buildaxis',    test_buildaxis    ) )
!    call add ( suite, TestCase1Step ( 'test_fileinitvtk',  test_fileinitvtk  ) )
    result = newTestResult ( mode=MODE_USE_STDOUT )

    call Run('triangle_mod', suite, result)

    call clean( result )
    call clean( suite )
end subroutine Run_Triangle_Tests


subroutine Test_Triangle_Create()
    type(PointObj)    :: pt1, pt2, pt3
    type(TriangleObj) :: tri
    pt1 = Point(0.0, 0.0, 0.0)
    pt2 = Point(1.0, 0.0, 0.0)
    pt3 = Point(0.0, 1.0, 0.0)
    tri = Triangle(pt1, pt2, pt3)
    call assertEqual(pt1, pt2, pt3, tri,"Triangle points")
    call assertEqual(0.5, tri%area, 1.0e-12, "Triangle area")
end subroutine Test_Triangle_Create

!> overload routine for pfUnit assert for TriangleObj
subroutine assertEqual_triobj(pt1, pt2, pt3, tri_in, mesg)
    type(PointObj),    intent(in) :: pt1
    type(PointObj),    intent(in) :: pt2
    type(PointObj),    intent(in) :: pt3
    type(TriangleObj), intent(in) :: tri_in
    character(len=*),  optional   :: mesg
    call assertEqual(pt1%x, pt1%y, pt1%z, tri_in%pt1, mesg)
    call assertEqual(pt2%x, pt2%y, pt2%z, tri_in%pt2, mesg)
    call assertEqual(pt3%x, pt3%y, pt3%z, tri_in%pt3, mesg)
end subroutine assertEqual_triobj


end module test_triangle_mod
